#include "pch.h"
#include "../Base.h"


BOOLEAN TranslateFileToHFile(char* filePath, char* outName) {

	FILE* file = NULL;

	fopen_s(&file, filePath, "rb");
	if (!file) {
		printf("文件不存在\r\n");
		return 0;
	}

	//求文件大小
	fseek(file, 0, SEEK_END);
	int len = ftell(file);
	//重设文件流指针
	rewind(file);
	UCHAR* fileBuffer = (UCHAR*)malloc(len);

	memset(fileBuffer, 0, len);
	fread_s(fileBuffer, len, len, 1, file);
	fclose(file);


	//创建一个文件 写入我们的硬编码
	if (!outName)
		fopen_s(&file, "dll.h", "wb");
	else
		fopen_s(&file, outName, "wb");

	if (file == NULL) {
		free(fileBuffer);
		return 0;
	}

	fputs("#pragma once\n", file);
	fprintf_s(file, "unsigned char sysData[%d] =    {\n", len);
	for (int i = 0;i < len; i++) {
		//fileBuffer[i] ^= 0x88;
		//fileBuffer[i] ^= 0x23;
		fprintf(file, "0x%02X, ", fileBuffer[i]);
		if ((i + 1) % 30 == 0) {
			fprintf_s(file, "\r\n");
		}
		
	}


	fprintf_s(file, "\r\n};");
	free(fileBuffer);
	fclose(file);
}